package com.hfut.wxy.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hfut.wxy.common.parent.ParentService;
import com.hfut.wxy.entity.mysql.WxyFeedback;
import com.hfut.wxy.entity.mysql.WxyUserInfo;
import com.hfut.wxy.service.IUserCenterService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class UserCenterService extends ParentService implements IUserCenterService  {
    @Override
    public Object completeInfo(WxyUserInfo wxyUserInfo) {
        return userDao.save(wxyUserInfo);
    }

    @Override
    public Object count(Integer userId) {
        JSONObject re = new JSONObject();
//        List<Integer> states = new ArrayList<>();
//        states.add(3);
//        states.add(6);
//        states.add(7);
        re.put("execute",orderDao.countAllByExecutorId(userId));

        re.put("create",orderDao.countAllByCreatorId(userId));

        re.put("cancelCreate",orderExceptionDao.countAllByUserIdAndIsOrderCreator(userId,true));

        re.put("cancelExecute",orderExceptionDao.countAllByUserIdAndIsOrderCreator(userId,false));
        return re;
    }

    @Override
    public Object feedback(WxyFeedback feedback) {
        feedBackDao.save(feedback);
        return true;
    }
}
